<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button class="btn1">存数据</button>
    <button class="btn2">获取数据</button>
    <button class="btn3">删除数据</button>
    <button class="btn4">删除所有数据</button>
    <script>
      let btn1 = document.querySelector(".btn1");
      let btn2 = document.querySelector(".btn2");
      let btn3 = document.querySelector(".btn3");
      let btn4 = document.querySelector(".btn4");
      //sessionStorage 和 localStorage 的区别
      //时效性  localStorage只要不人为删除 就会永久存储
      //        sessionStorage 关闭浏览器就会自动销毁
      btn1.onclick = function () {
        sessionStorage.setItem("myname", "value");
      };
      btn2.onclick = function () {
        console.log(sessionStorage.getItem("myname"));
      };
      btn3.onclick = function () {
        sessionStorage.removeItem("myname");
      };
      btn4.onclick = function () {
        sessionStorage.clear();
      };
    </script>
  </body>
</html>
